package com.pactera.miyuangroup.controller.web;

import com.baomidou.mybatisplus.plugins.Page;
import com.pactera.miyuangroup.filter.CurrentUser;
import com.pactera.miyuangroup.service.VehicleInfoService;
import com.pactera.miyuangroup.vo.request.web.VehicleInfoRequest;
import com.pactera.miyuangroup.vo.response.ResultModel;
import com.pactera.miyuangroup.vo.response.ResultStatusCode;
import com.pactera.miyuangroup.vo.response.User;
import com.pactera.miyuangroup.vo.response.VoidResponse;
import com.pactera.miyuangroup.vo.response.web.MenuRes;
import com.pactera.miyuangroup.vo.response.web.VehicleInfoRes;
import com.pactera.miyuangroup.vo.response.web.VendorInfoRes;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 描述:
 *
 * @outhor 张汉卿
 * @create 2018-04-24 10:08
 */

@Api(description = "车辆信息")
@RestController
@RequestMapping("VehicleInfo")
public class VehicleInfoController {

    @Autowired
    private VehicleInfoService vehicleInfoService;

    /*
    *查询车辆信息
    * */

    @ApiOperation(value="车辆信息列表", notes="车辆信息列表")
    @RequestMapping(value = "/list", method = RequestMethod.POST)
    private ResultModel<Page<VehicleInfoRes>> getList(@RequestBody VehicleInfoRequest vehicleRequest,@CurrentUser User user){


        Page<VehicleInfoRes> vehicleInfoList = vehicleInfoService.getVehicleInfoList(vehicleRequest,user.getOrgId());

        return ResultModel.ok(vehicleInfoList);
    }


    /*
    * 车辆线路的售货机列表
    * */
    @ApiOperation(value="车辆线路的售货机列表", notes="车辆线路的售货机列表")
    @ApiImplicitParams({@ApiImplicitParam(value = "车辆ID", name = "vehicleId", required = true, paramType = "path")})
    @RequestMapping(value = "/getVendorInfoList/{vehicleId}", method = RequestMethod.GET)
    public ResultModel<List<VendorInfoRes>> getVendorInfoList(@PathVariable String vehicleId) {
        List<VendorInfoRes> vendorInfoList = vehicleInfoService.getVendorInfoList(vehicleId);

        return ResultModel.ok(vendorInfoList);
    }

    @ApiOperation(value = "同步车辆信息", notes = "同步车辆信息")
    @RequestMapping(value = "/syncVehicleInfo", method = RequestMethod.GET)
    public ResultModel<VoidResponse> syncVehicleInfo() {
        boolean flg = vehicleInfoService.syncMiyuanVehicleInfo();
        if (!flg) {
            return ResultModel.warning(ResultStatusCode.DATA_IS_SYNC);
        }
        return ResultModel.ok();
    }

}
